﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Show_LED_New
{
    public partial class StartView : SubView
    {
        private string now_button_name = "mainButton1";
        public StartView()
        {
            InitializeComponent();
            // 设置按钮之间的关系
           
        }
        
        public void Set_Button()
        {
            mainButton1.right_to = "mainButton2";
            mainButton2.left_to = "mainButton1";
            mainButton2.enter_view = MainView.xinxiChaxun;
            Set_Select_Button(now_button_name);
        }

        private void Set_Select_Button(string buttonname)
        {
            foreach(Control mybutton in this.Controls)
            {
                if (buttonname == mybutton.Name)
                {
                    MainButton mymainbutton = (MainButton)mybutton;
                    mymainbutton.button_selected();
                }
                else
                {
                    MainButton mymainbutton = (MainButton)mybutton;
                    mymainbutton.button_cancel();
                }
            }
            now_button_name = buttonname;
        }

        private void Get_Next_Button(string fangxiang)
        {
            // 查询上下左右的按键是哪一个
            foreach(Control mycontrol in this.Controls)
            {
                if(mycontrol.Name==now_button_name)
                {
                    try
                    {
                        MainButton mybutton = (MainButton)mycontrol;
                        if (fangxiang == "上" && mybutton.up_to != null) { Set_Select_Button(mybutton.up_to); return; }
                        if (fangxiang == "左" && mybutton.left_to != null) { Set_Select_Button(mybutton.left_to); return; }
                        if (fangxiang == "下" && mybutton.down_to != null) { Set_Select_Button(mybutton.down_to); return; }
                        if (fangxiang == "右" && mybutton.right_to != null) { Set_Select_Button(mybutton.right_to); return; }
                        if(fangxiang=="确定" && mybutton.enter_view!=null)
                        {
                            MainView mv = (MainView)this.Parent.Parent;
                            mv.ReSet_View(mybutton.enter_view);
                        }
                    }
                    catch { }
                    break;
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        public override void Receive(string cmd)
        {
           // 重写Receive函数
            Get_Next_Button(cmd);
        }
    }
}
